﻿Imports Global_Visas_Business_Layer
Imports System.ComponentModel
Partial Public Class frmSendSMS

    Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSend.Click
        Dim tsk As New Global_Visas_Business_Layer.TasksEvents
        Try

            If Me.txtNumber.Text.Trim = String.Empty Then
                CommonFuncs.DisplayMessage("Please enter a valid mobile phone number", CommonDialog.CustomDialogIcons.Information, "Phone Number")
                Me.txtNumber.Focus()
                Exit Sub
            End If

            If Me.txtMessage.Text.Trim = String.Empty Then
                CommonFuncs.DisplayMessage("Please enter a valid content", CommonDialog.CustomDialogIcons.Information, "Message")
                Me.txtMessage.Focus()
                Exit Sub
            End If
            Dim strWebAddress As String = CommonDataFunctions.GetBranchSMSLink(GlobalCRM.CurrentCaseID)
            If strWebAddress = String.Empty Then
                CommonFuncs.DisplayMessage("The SMS Link is not configured for your Branch. Please contact your manager or IT for more information.", CommonDialog.CustomDialogIcons.Information, "SMS")
                Me.Close()
                '        End If
                Exit Sub
            Else
                Dim strAddr As String = Replace(strWebAddress, "<%1>", Me.txtNumber.Text.Trim, , , CompareMethod.Text)
                strWebAddress = Replace(strAddr, "<%2>", Me.txtMessage.Text.Trim)


                If Mid(strWebAddress, 1, 7) = "http://" Then
                    ' do nothing
                Else
                    strWebAddress = "http://" & strWebAddress
                End If
                tsk.GblFunc_Add_Event("SMS Sent", "Phone Number : " & Me.txtNumber.Text & vbCrLf & "Message : " & Me.txtMessage.Text, TasksEvents.EventStatus.SingleEvent, GlobalCRM.CurrentCaseID, TasksEvents.EventTypes.EventCase)
                System.Diagnostics.Process.Start(strWebAddress)

            End If
            Me.Close()

        Catch ex As Exception

        Finally
            tsk = Nothing
        End Try
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub

    Private Sub frmSendSMS_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        GeneralTasks.ChangeTheme(Me)
        GeneralTasks.EnumerateandFill(Me.LogicalChildren)
        With Me.cboTemplate
            .SelectedValuePath = "SMSTemplate_id"
            .DisplayMemberPath = "SMSTemplate_Name"
            .ItemsSource = CType(CommonDataFunctions.GetSMSTemplates(CommonDataFunctions.GetBranchIDFromCase(GlobalCRM.CurrentCaseID)), IListSource).GetList()
            .SelectedIndex = 0
        End With
    End Sub

    Private Sub cboTemplate_SelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs) Handles cboTemplate.SelectionChanged
        Dim s As String = Letters.Gblfunc_Process_Bookmarks(cboTemplate.SelectedItem, GlobalCRM.CurrentCaseID, 1)
    End Sub
End Class
